/**
 * 30APR12
 * I listen to your keys...
 */

package main;
import java.awt.KeyEventDispatcher;
import java.awt.event.KeyEvent;

public class KeyListeningBandit implements KeyEventDispatcher {
	TurnManager t;
	Unit u;

	/**
	 * constructor
	 * @param turnMgr - turn manager
	 * @param unit - selected unit
	 */
	public KeyListeningBandit(TurnManager turnMgr, Unit unit) {
		super();
		t = turnMgr;
		u = unit;
	}

	/**
	 * updates selected unit
	 * @param unit - unit
	 */
	public void updateUnit(Unit unit) {
		u = unit;
	}

	/**
	 * listens to keys! launches windows as appropiate
	 */
	public boolean dispatchKeyEvent(KeyEvent e) {
		if (e.getID() == KeyEvent.KEY_TYPED) {
			if(e.getKeyChar() == 't' && !(t.techSet)) {
				t.techSet = true;
				new TechSelector(t.active);
			} else if(e.getKeyChar() == 'i' && u != null && !u.infoOpen) {
				u.infoOpen = true;
				new UnitInfo(u);
			} else if(e.getKeyChar() == 'r' && !t.active.resPane) {
				t.active.resPane = true;
				new ResourcePanel(t);
			} else if(e.getKeyChar() == 'p' && !t.active.polSlider) {
				t.active.polSlider = true;
				new PoliticalSliders(t.active);
			}
		}
		return false;
	}
} 